﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TSTreeThesis.Utilities
{
  public class DTWTransform
    {
      public double[] d_lower;
      public double[] d_upper;

      public float[] f_lower;
      public float[] f_upper;
      public void Transform(int r, double[] points)
      {
          d_lower = new double[points.Length];
          d_upper = new double[points.Length];

          for (int i = 0; i < points.Length; i++)
          {
              int startIndex = i - r < 0 ? 0 : i - r;
              int length = startIndex + r * 2 < points.Length ? r * 2 : points.Length - startIndex;

              var newArray = new double[length];
              Array.Copy(points, startIndex , newArray, 0, length);

              this.d_upper[i] = newArray.Max();
              this.d_lower[i] = newArray.Min();
          }

      }

      public void Transform(int r, float[] points)
      {
          f_lower = new float[points.Length];
          f_upper = new float[points.Length];

          for (int i = 0; i < points.Length; i++)
          {
              int startIndex = i - r < 0 ? 0 : i - r;
              int length = startIndex + r * 2 < points.Length ? r * 2 : points.Length - startIndex;

              var newArray = new float[length];
              Array.Copy(points, startIndex, newArray, 0, length);

              this.f_upper[i] = newArray.Max();
              this.f_lower[i] = newArray.Min();
          }
      }
    }
}
